package br.com.gbvbahia.mybooks;

import java.util.List;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import br.com.gbvbahia.mybooks.dao.PrateleiraDAO;

public class ListarPrateleiras extends ListActivity{

	public static final String RESULT_PRATELEIRA = "prateleira";
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		PrateleiraDAO dao = new PrateleiraDAO(getApplicationContext());
		List<String> prateleiras = dao.buscarPrateleirasNomes();
		setListAdapter(new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_list_item_1, prateleiras));
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		setResult(RESULT_OK, new Intent().putExtra(RESULT_PRATELEIRA, l.getAdapter().getItem(position).toString()));
		finish();
	}

}
